/**
    入驻小区
**/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            communityPaymentInfo: {
                payments: [],
                paymentTypes:[],
                total: 0,
                records: 1,
                moreCondition: false,
                ppId: '',
                conditions: {
                    paymentName: '',
                    paymentType: '',
                    state: '',
                    communityId:''
                }
            }
        },
        _initMethod: function () {
            vc.on('selectAdminCommunity','changeCommunity',function(_community){
                $that.communityPaymentInfo.conditions.communityId = _community.communityId;
                $that._listCommunityPayments(DEFAULT_PAGE, DEFAULT_ROWS);
            })
            $that._listCommunityPayments(DEFAULT_PAGE, DEFAULT_ROWS);
        },
        _initEvent: function () {

            vc.on('communityPayment', 'listCommunityPayment', function (_param) {
                $that._listCommunityPayments(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that._listCommunityPayments(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _listCommunityPayments: function (_page, _rows) {

                $that.communityPaymentInfo.conditions.page = _page;
                $that.communityPaymentInfo.conditions.row = _rows;
                let param = {
                    params: $that.communityPaymentInfo.conditions
                };

                //发送get请求
                vc.http.apiGet('/payment.listAdminPayment',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.communityPaymentInfo.total = _json.total;
                        $that.communityPaymentInfo.records = _json.records;
                        $that.communityPaymentInfo.payments = _json.data;
                        vc.emit('pagination', 'init', {
                            total: $that.communityPaymentInfo.records,
                            currentPage: _page
                        });
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _openAddCommunityPaymentModal: function () {
                vc.emit('addCommunityPayment', 'openAddCommunityPaymentModal', {
                    communityId:$that.communityPaymentInfo.conditions.communityId,
                });
            },
            _openEditCommunityPaymentModel: function (_communityPayment) {
                vc.emit('editCommunityPayment', 'openEditCommunityPaymentModal', _communityPayment);
            },
            _openDeleteCommunityPaymentModel: function (_communityPayment) {
                vc.emit('deleteCommunityPayment','openDeleteCommunityPaymentModal', _communityPayment);
            },
            _queryCommunityPaymentMethod: function () {
                $that._listCommunityPayments(DEFAULT_PAGE, DEFAULT_ROWS);

            },
            _moreCondition: function () {
                if ($that.communityPaymentInfo.moreCondition) {
                    $that.communityPaymentInfo.moreCondition = false;
                } else {
                    $that.communityPaymentInfo.moreCondition = true;
                }
            },
        }
    });
})(window.vc);
